function MbCommon($,header) {
	var Mb = Mb || {};
    var _Common_Config = {
        // host:'',
        isDebug:false,
        // domain:"/",
         host:'https://www.acdelco.com.cn',
         //host:'http://192.168.0.117:8081',
        //  isDebug:true,
         domain:"https://www.acdelco.com.cn/",
         domainGas:"https://www.acdelco.com.cn/bsxImage/"
    };
    Mb.Config = _Common_Config;
	Mb.init = function(){
		header.init();
	};
    Mb.toast = function(message,callback){
        $(".toast").html(message);
        $(".toast").fadeIn();
        setTimeout(function(){
            $(".toast").fadeOut();
            if(callback){
                callback.call();
            }
        },1000);
    };
	Mb.utils = function () {
        var utils = utils || {
            formatDate:function (timeStamp) {
                if(!timeStamp){
                    return "";
                }
                function zeroBu(n){
                    if(n<10){
                        return '0'+n;
                    }else{
                        return n
                    }
                }
                var time = new Date(timeStamp);
                var y = zeroBu(time.getFullYear());//年
                var m = zeroBu(time.getMonth() + 1);//月
                var d = zeroBu(time.getDate());//日
                var h =zeroBu( time.getHours());//时
                var mm =zeroBu( time.getMinutes());//分
                var s = zeroBu(time.getSeconds());//秒
                var times=y+"-"+m+"-"+d+" "+h+":"+mm+":"+s;
                return times;
            },
            formatDateYYmmdd:function (timeStamp) {
                if(!timeStamp || timeStamp == "" || $.trim(timeStamp) == ""){
                    return "";
                }

                function zeroBu(n){
                    if(n<10){
                        return '0'+n;
                    }else{
                        return n
                    }
                }
                var time = new Date(timeStamp);
                var y = zeroBu(time.getFullYear());//年
                var m = zeroBu(time.getMonth() + 1);//月
                var d = zeroBu(time.getDate());//日
                var times=y+"-"+m+"-"+d;
                return times;
            },
            formatDateYYmm:function (timeStamp) {
                if(!timeStamp || timeStamp == "" || $.trim(timeStamp) == ""){
                    return "";
                }

                function zeroBu(n){
                    if(n<10){
                        return '0'+n;
                    }else{
                        return n
                    }
                }
                var time = new Date(timeStamp);
                var y = zeroBu(time.getFullYear());//年
                var m = zeroBu(time.getMonth() + 1);//月
                var times=y+"-"+m;
                return times;
            },
            // 是否为IE78
            browserIe: function () {
                var explorer = navigator.userAgent;
                //ie
                if (explorer.indexOf("MSIE") >= 0) {
                    return true;
                } else {
                    return false;
                }
            },
            // 随机码
            randomWord: function (size) {
                var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
                var res = "";
                for (var i = 0; i < size; i++) {
                    var id = Math.ceil(Math.random() * 35);
                    res += chars[id];
                }
                return res;
            },
            // 手机号码替换 134555554444 -> 134****4444
            phonenoReplace: function (phoneno, start, length, replaceFlg) {
                start = start ? start : 3;
                length = length ? length : 4;
                replaceFlg = replaceFlg ? replaceFlg : "*";
                var replaceStr = "";
                for (var i = 0; i < length; i++) {
                    replaceStr = replaceStr + replaceFlg;
                }
                return phoneno ? phoneno.substr(0, start) + replaceStr + phoneno.substr(start + length) : replaceStr;
            },
            // 字符串是否以（startWith）开始
            isStrStartWith: function (str, startWith) {
                if (!str || !startWith) return false;
                var len = startWith.length;
                return str.substr(0, len) == startWith;
            },
            //获得字符串的后几位
            getEndStr: function (str, len) {
                return str ? str.substr(-1 * len) : "";
            },
            urlParam: function (param) {
                return this.urlParamWithFixed(location.href, param);
            },
            // 链接中的参数params[可以为数组]
            urlParams: function (params) {
                return this.urlParamsWithFixed(location.href, params);
            },
            urlParamWithFixed: function (url, param) {
                if (!param) return "";
                var pattern = new RegExp("[?&]" + param + "\=([^&]+)", "g");
                var matcher = pattern.exec(url);
                var res = "";
                if (null !== matcher) {
                    try {
                        res = decodeURIComponent(decodeURIComponent(matcher[1]));
                    } catch (e) {
                        try {
                            res = decodeURIComponent(matcher[1]);
                        } catch (e) {
                            res = matcher[1];
                        }
                    }
                }
                if (res) {
                    res = res.indexOf("#") > 0 ? res.substr(0, res.indexOf("#")) : res;
                }
                return res;
            },
            // 链接中的参数
            urlParamsWithFixed: function (url, params) {
                if (!params) return "";
                var searchParmas;
                if (params instanceof Array) {
                    searchParmas = params;
                } else if (params instanceof String) {
                    searchParmas = [params];
                } else {
                    return "";
                }
                var res = {};
                for (var key in searchParmas) {
                    res[searchParmas[key]] = this.urlParamWithFixed(url, searchParmas[key]);
                }
                return res;
            },
            // 将对象转成url的参数信息
            toUrlParams: function (obj) {
                if (!obj) return "";
                var paramStr = "";
                $.each(obj, function (i, item) {
                    if (item.value != undefined) {
                        if (paramStr) {
                            paramStr += "&" + item.key + "=" + item.value;
                        } else {
                            paramStr = item.key + "=" + item.value;
                        }
                    }
                });
                return paramStr;
            },
            // 是否有url参数
            hasUrlParams: function (url) {
                return url ? url.indexOf("?") >= 0 : false;
            },
            // 日期间隔 目前只支持yyyy-MM-dd yyyy/MM/dd
            dateDiff: function (dateTime1, dateTime2) {
                var beginTime = new Date(dateTime1.pattern("yyyy-MM-dd").replace(/-/g, "/"));
                var endTime = new Date(dateTime2.pattern("yyyy-MM-dd").replace(/-/g, "/"));
                var days = Math.abs((beginTime - endTime)) / (1000 * 60 * 60 * 24);
                return days;
            },
            // 当前日期多少天以后的日期
            daysAfter: function (days) {
                return this.daysAfterWithFixed(new Date(), days);
            },
            // 指定日期的多少天之后日期
            daysAfterWithFixed: function (startDate, days) {
                var beginTime = new Date(fromTime.pattern("yyyy-MM-dd").replace(/-/g, "/"));
                var addTime = days * 1000 * 60 * 60 * 24;
                return new Date(beginTime + addTime);
            },
            // str -> 日期
            str2Date: function (str) {
                try {
                    return new Date(str.replace(/-/g, "/"));
                } catch (e) {
                    console.warn(e.message);
                    return null;
                }
            },
            // 日期 -> str
            date2Str: function (date, formatString) {
                return date.pattern(formatString);
            },
            json2Str: function (o) {
                var arr = [];
                var fmt = function (s) {
                    if (typeof s == 'object' && s != null) return json2str(s);
                    return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
                }
                for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
                return '{' + arr.join(',') + '}';
            },
            str2Json: function (stringValue) {
                eval("var theJsonValue = " + stringValue);
                return theJsonValue;
            },
            // 金额格式化
            formatAmount: function (amount, intLen, floatLen) {
                if (!amount) return "0.00";
                intLen ? void(0) : intLen = 3;
                floatLen == 0 ? void(0) : floatLen = 2;
                amount = Math.round(parseFloat((amount + "").replace(/[^\d\.-]/g, "")) * 100) / 100;
                amount = amount + "";
                var intArr = amount.split(".")[0].split("").reverse(), fval = amount.split(".")[1], intStr = "";
                for (i = 0; i < intArr.length; i++) {
                    intStr += intArr[i] + ((i + 1) % intLen == 0 && (i + 1) != intArr.length ? "," : "");
                }
                if (floatLen && floatLen != 0) {
                    if (fval) {
                        for (i = fval.length + 1; i <= floatLen; i++) {
                            fval += "0";
                        }
                        fval = "." + fval;
                    } else {
                        fval = ".00";
                    }
                } else {
                    fval = "";
                }
                intStr = intStr.split("").reverse().join("");
                intStr = intStr + fval;
                return intStr;
            },
            // 投资金额输入框 只能输入数字
            validateNumberOnly: function (e, amount) {
                if (!/^\d+$/.test(amount)) {
                    e.value = /^\d+/.exec(e.value);
                    if (e.value == "null") {
                        e.value = "";
                    }
                }
            },
            //格式化金额 
            getAmount: function (amount) {
                var _this = this;
                var unit = "";
                if (amount >= 10000) {
                    amount = _this.formatAmount(amount / 10000, 3, 2).replace(".00", "");
                    unit = "万元";
                } else {
                    amount = _this.formatAmount(amount, 3, 0);
                    unit = "元";
                }
                return [amount, unit];
            },
            //取消字符串中出现的所有逗号
            replaceCommaWithEmpty: function (amount) {
                if (!amount) return "";
                return amount.replace(/,/g, "");
            },
            // 跳转
            windowJump: function (url, isReplaceUrl) {
                if (!url) url = "/";
                if (isReplaceUrl) {
                    window.location.replace(url);
                } else {
                    window.location.href = url;
                }
            },
            windowJumpToStep: function (step) {
                if (step) window.location.hash = step;
            },
            requestServerJump: function (url) {
                if (!url) url = "/";
                if (_Common_Config.isDebug) {
                    window.location.href = _Common_Config.host + url;
                } else {
                    window.location.href = url;
                }
            },
            // 阻止浏览器默认效果的触发
            pervent: function (e) {
                if (e && e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    window.event.cancelBubble = true;
                }
                if (e && e.preventDefault) {
                    e.preventDefault();
                }
                else {
                    window.event.returnValue = false;
                }
                return false;
            },
            htmlencode: function (s) {
                var div = document.createElement('div');
                div.appendChild(document.createTextNode(s));
                return div.innerHTML;
            },
            htmldecode: function (s) {
                var div = document.createElement('div');
                div.innerHTML = s;
                return div.innerText || div.textContent;
            },
            uniqueArr:function(arr) {
               var tmp = new Array();
                if(arr && arr.length ==0){
                    return tmp;
                }
                for ( var i in arr) {
                    if (tmp.indexOf(arr[i]) == -1) {
                        if(arr.hasOwnProperty(i)){
                            tmp.push(arr[i]);
                        }
                    }
                }
                return tmp;
            },
            sortArr:function (keyArr) {
                var tmp1 = keyArr[0];
                var pattern = /^(\d+(\.\d+)?)$/;
                var patternSpec = /^(\d+(\.\d+)?)/gi;
                var patternGrp = /(\d+)/g;
                if(pattern.test(tmp1)){ //数字
                    keyArr.sort(function(a,b){
                        return a - b;
                    });
                }else if(patternSpec.test(tmp1)){
                    keyArr.sort(function(a,b){
                        var tmpAArr = a.match(patternGrp);
                        var tmpBArr = b.match(patternGrp);
                        if(tmpAArr.length == 1 && tmpBArr.length == 1){
                            var tmpA1 = tmpAArr[0];
                            var tmpB1 = tmpBArr[0];
                            return tmpA1 - tmpB1;
                        }else{
                            var tmpA2 = "1";
                            var tmpB2 = "0";
                            if(tmpAArr.length > 1){
                                tmpA2 = tmpAArr[1];
                            }
                            if(tmpBArr.length > 1){
                                tmpB2 = tmpBArr[1];
                            }
                            var tmpA1 = a.match(patternSpec)[0];
                            var tmpb1 = b.match(patternSpec)[0];
                            if( tmpA1 == tmpb1){
                                return tmpA2 - tmpB2;
                            }
                            else
                            {
                                return tmpA1 - tmpb1;
                            }
                        }
                    });
                }
                else{
                    keyArr.sort();
                }
                return keyArr;
            },
            textIfEmpty:function(txt,defaultVal){
                if(!txt){
                    return defaultVal || "";
                }
                var txt = $.trim(txt);
                if(!txt){
                    return defaultVal || "";
                }
                return txt;
            }
        };
        return utils;
    };
        // ajax 应放在utils,由于特殊性单独放出
    Mb.ajax =  function (option) {
            var _this = this;
            if (!$ in window || !option) return;
            if (!option.url || !$.trim(option.url)) {
                return;
            }
            var url = option.url;
            if (_Common_Config.isDebug) {
                url = _Common_Config.host + url;
            }
            //option.loadingContainer = option.loadingContainer || $(".page-loading");
            if (option.loadingContainer) {
                option.loadingContainer.addClass("loading");
            }else{
                if($(".page-loading-info").hasClass("with-txt")){
                   option.loadingtext = option.loadingtext || "";
                   $(".page-loading-info-con").find(".info").text(option.loadingtext);
                }
                $(".page-loading").show().addClass("loading");
            }
            //预留接口,又来做token验证
            var CheckToken = function () {
                return true;
            };
            var DefBeforeSend = function () {
                if (!CheckToken()) {
                    return false;
                }
                if (option.beforeSend) {
                    option.beforeSend.call(this);
                }
                return true;
            },
            params = {
                url: url,
                type: option.type ? option.type : "get",
                beforeSend: DefBeforeSend,
                loadingContainer: null
            };
            if(option.isMultiPart){
                params.contentType = false;
                params.processData = false
            }
            params.dataType = option.dataType ? option.dataType : 'json';
            if (option.data) params.data = option.data;
            if (option.async != undefined) params.async = option.async;
            var responseData;
            params.success = function (data, status, xhr) {
                responseData = data;
                if (option.success) {
                    option.success.call(this, responseData, status);
                } else {
                    return true;
                }
            },
           params.error = function (xhr, errorType, error) {
                closeLoading();
                // 自定义错误处理时,回调
                if (option.error) {
                    var data = {
                        code: "error",
                        message: "",
                        status: xhr.status
                    };
                    option.error.call(this, data, errorType);
                    return;
                }
            },
            params.complete = function () {
                closeLoading();
                if (option.complete) option.complete.call(this, responseData);
            };

            function closeLoading() {
                if (option.loadingContainer) {
                    option.loadingContainer.removeClass("loading");
                }else{
                    $(".page-loading").hide().removeClass("loading");
                }
            }

            try {
                $.ajax(params);
            } catch (e) {

            }

    };
    
    return Mb;
    
}
if ("function" == typeof define && define.amd && define) {
    define(['zepto', 'common/header'], function ($, header) {
        return MbCommon($, header);
    });
}